﻿/*
 * 确认报价
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Company_ConfirmBid : System.Web.UI.Page, IAccess
{
    string action = "";
    protected string link = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentAccount.CheckSessionTimeOut(this);
        action = (Request.QueryString["action"] ?? "").ToLower();
        if (CurrentAccount.IsConfirmBid)
        {
            Response.Redirect(string.Format("PrePrintPrice.aspx?action={0}", action));
        }

        SetNav();
        SetLink();
        if (!IsPostBack)
        {
            if (action == "bid")
            {

                BindData();
                //if (CurrentProject.InBidTime == -1)
                //{
                //    lblBidPriceStatus.Text = "未开始报价。";
                //    //HZ.Web.WebUtil.Alert("未开始报价。");
                //}
                //else if (CurrentProject.InBidTime == 1)
                //{
                //    //HZ.Web.WebUtil.Alert("报价已经结束，不能再进行报价。");
                //    lblBidPriceStatus.Text = "报价时间已经结束，不能再进行报价。";
                //    return;
                //}
                //else {
                //    lblBidPriceStatus.Text = "报价进行中。";
                //}
            }


            if (action == "bargain")
            {

                BindBargain();
            }
            HZ.BidSystem.BLL.BLL_Cache.SetOnlineModel(CurrentAccount.Account.AccountId.Value, new HZ.BidSystem.Model.OnLineModel() { Active = "正在确认报价" });
        }
    }

    private void SetLink()
    {
        //update by hw20110719 报价确认 要提示2次
        link = string.Format("CheckBidPwd2.aspx?action={0}&action2=confirmbid", action);
    }
    /// <summary>
    /// 设置导航栏
    /// </summary>
    private void SetNav()
    {
        switch (action)
        {
            case "bargain":
                CompanyNavigation1.BidType = HZ.BidSystem.Model.BidType.Bargain;
                break;

            case "compete":
                CompanyNavigation1.BidType = HZ.BidSystem.Model.BidType.Compete;
                break;
            default:
                CompanyNavigation1.BidType = HZ.BidSystem.Model.BidType.Bid;
                break;
        }
    }

    #region IAccess Members

    IList<EnumAccess> IAccess.AccessList
    {
        get
        {
            var list = new List<EnumAccess>();
            list.Add(EnumAccess.Company);
            return list;
        }

    }

    #endregion
    protected void btnNext_Click(object sender, EventArgs e)
    {
        
        if (!CurrentProject.IsBidSwitch)
        {
            HZ.Web.MessageBox.Show("报价开关未开启，无法进行确认报价。");
            return;
        }
        if (CurrentProject.InBidTime<0)
        {
            HZ.Web.MessageBox.Show("报价时间未到，无法进行确认报价。");
            return;
        }
        if (CurrentProject.InBidTime > 0)//判断是否报价时间过期
        {
            HZ.Web.WebUtil.Alert("报价时间已过，无法进行确认报价！", this);
        }
        else
        {
            // 是否还有品规未报价。

            int nobidcount = BLL_Factory.IBLL_Company.GetNoBidCount();
            if (nobidcount > 0 ) // 报价时间未过可以报价时阻止确认，否则直接确认。 禁止在此处加上&& action == "bid"  防止用户在打印产品页面直接进行跳转或把action清空 by yjx 2016年7月15日 15:37:09
            {
                HZ.Web.WebUtil.Alert(string.Format("您有{0}个未报价品规，若您确定不想报价，请报0弃标。系统已阻止您确认报价。", nobidcount), this);
            }
            else
            {
                Response.Redirect(link);
            }
        }
    }

    private void BindData()
    {
        int totalrecord;
        //页面翻页 by何炜骅
        var ds = BLL_Factory.IBLL_Company.GetBidPriceWithDec(new HZ.BidSystem.Model.QBidPrice() { CompanyId_Tb = CurrentAccount.Account.AccountId.Value, SortFields = "Company_Goods" }, pager1.CurrentPage, pager1.PageSize, out totalrecord, CurrentAccount.BidPwd, CurrentAccount.RandPwd);
        pager1.RecordCount = totalrecord;
        gvresult.DataSource = ds;
        gvresult.DataBind();
    }

    private void BindBargain()
    {
        int totalrecord;
        //页面翻页 by何炜骅
        var ds = BLL_Factory.IBLL_Company.GetBargainWithDec(new HZ.BidSystem.Model.QBidPrice() { CompanyId_Tb = CurrentAccount.Account.AccountId.Value, SortFields = "Company_Goods" }, pager1.CurrentPage, pager1.PageSize, out totalrecord, CurrentAccount.BidPwd, CurrentAccount.RandPwd);
        pager1.RecordCount = totalrecord;
        gvbargainresult.DataSource = ds;
        gvbargainresult.DataBind();
    }
    protected void gvbargainresult_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }
    protected void pager1_PageChanging(object sender, HZ.Web.PageChaningEventArgs e)
    {
        BindData();
    }
}
